<template>
  <div>
    <van-cell class="comment-item">
      <van-image
        slot="icon"
        class="avatar"
        round
        fit="cover"
        :src="comment.aut_photo"
      />
      <div slot="title" class="title-wrap">
        <div class="user-name">{{ comment.aut_name }}</div>
        <van-button
          @click="likeHandle"
          class="like-btn"
          :class="{
            liked: comment.is_liking
          }"
          :icon="comment.is_liking ? 'good-job' : 'good-job-o'"
          :loading="commentLoading"
          >{{ comment.like_count || "赞" }}</van-button
        >
      </div>

      <div slot="label">
        <p class="comment-content">{{ comment.content }}</p>
        <div class="bottom-info">
          <span class="comment-pubdate">{{ comment.pubdate | format }}</span>
          <van-button
            @click="$emit('showpost2', comment)"
            class="reply-btn"
            round
            >回复 {{ comment.reply_count }}</van-button
          >
        </div>
      </div>
    </van-cell>
  </div>
</template>

<script>
import { addCommentLikeApi, deleteCommentLikeApi } from "@/api";
export default {
  components: {},
  model:{
    prop:'is_liking',  //  value
    event:'likevent'
  },
  props: {
    is_liking:{},
    comment: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      commentLoading: false
    };
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    async likeHandle() {
      //  对评论进行点赞和取消

      // this.comment.is_liking=


      //  判断是需要点赞还是取消点赞
      if (this.is_liking) {
        //  已经点赞===取消
        this.comment.like_count--
        const { data: res } = await deleteCommentLikeApi(this.comment.com_id);
      } else {
        //  需要点赞
        this.comment.like_count++
        const { data: res } = await addCommentLikeApi(this.comment.com_id);
        console.log();
      }

      this.$emit('likevent',!this.is_liking)
    }
  }
};
</script>

<style scoped lang="less">
.comment-item {
  .avatar {
    width: 72px;
    height: 72px;
    margin-right: 25px;
  }
  .title-wrap {
    display: flex;
    justify-content: space-between;
    align-items: center;
    .user-name {
      color: #406599;
      font-size: 26px;
    }
  }
  .comment-content {
    font-size: 32px;
    color: #222222;
    word-break: break-all;
    text-align: justify;
  }
  .comment-pubdate {
    font-size: 19px;
    color: #222;
    margin-right: 25px;
  }
  .bottom-info {
    display: flex;
    align-items: center;
  }
  .reply-btn {
    // width: 135px;
    height: 48px;
    line-height: 48px;
    font-size: 21px;
    color: #222;
  }
  .like-btn {
    height: 30px;
    padding: 0;
    border: none;
    font-size: 19px;
    line-height: 30px;
    margin-right: 7px;
    .van-icon {
      font-size: 30px;
    }
    &.liked {
      color: #e5645f;
    }
  }
}
</style>
